package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolChildMaterialPageAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolChildMaterialUpdateSortAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolMaterialChildSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolMaterialNotChildIdPageListDTO;
import com.sc.nft.entity.vo.DaoSchoolChildMaterialNotPageAdminVO;
import com.sc.nft.entity.vo.DaoSchoolChildMaterialPageAdminVO;
import com.sc.nft.service.DaoSchoolChildMaterialService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 素材表与子集关联表(DaoSchoolChildMaterial)表控制层
 *
 * @author makejava
 * @since 2023-03-15 18:09:13
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolChildMaterial")
@Api(tags = "素材关联")
public class DaoSchoolChildMaterialController {

    /**
     * 服务对象
     */
    private final DaoSchoolChildMaterialService daoSchoolChildMaterialService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolChildMaterialPageAdminVO> pageAdmin(@RequestBody DaoSchoolChildMaterialPageAdminDTO pageRequest) {
        Page<DaoSchoolChildMaterialPageAdminVO> daoSchoolArticleChildPageAdminVOPage = daoSchoolChildMaterialService.pageAdmin(pageRequest);
        return PageResult.success(daoSchoolArticleChildPageAdminVOPage);
    }

    @ApiOperation(value = "素材关联删除", notes = "文章关联删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Validated IdRequest idRequest) {
        daoSchoolChildMaterialService.deleteById(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "获取没有被某个子集选中的素材", notes = "获取没有被某个子集选中的素材", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectByNotChildIdPageList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolChildMaterialNotPageAdminVO> selectByNotChildIdPageList(@RequestBody DaoSchoolMaterialNotChildIdPageListDTO dto) {
        Page<DaoSchoolChildMaterialNotPageAdminVO> daoSchoolArticleChildPageAdminVOPage = daoSchoolChildMaterialService.selectByNotChildIdPageList(dto);
        return PageResult.success(daoSchoolArticleChildPageAdminVOPage);
    }

    @ApiOperation(value = "素材关联新增", notes = "文章关联新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@RequestBody @Validated List<DaoSchoolMaterialChildSaveAdminDTO> info) {
        daoSchoolChildMaterialService.saveAdmin(info);
        return Result.success();
    }

    @ApiOperation(value = "修改排序", notes = "修改排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSortById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSortById(@RequestBody @Validated DaoSchoolChildMaterialUpdateSortAdminDTO info) {
        daoSchoolChildMaterialService.updateSortById(info);
        return Result.success();
    }

}
